package org.onionframework.persistence.extend;

import org.hibernate.SessionFactory;
import org.hibernate.annotations.common.reflection.MetadataProviderInjector;
import org.onionframework.core.util.Reflections;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;

public class OnionSessionFactoryBean extends LocalSessionFactoryBean {

	protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) {
		Reflections.setFieldValue(( ( MetadataProviderInjector )sfb.getReflectionManager()).getMetadataProvider(), 
				"delegate", new OnionMetadataProvider());
		
		return  sfb.buildSessionFactory();
	}
}
